package com.starblink.library.data.transfer

import android.content.Context
import android.util.Log
import com.starblink.android.basic.config.StorageKeys
import com.starblink.basic.storage.SkStorage

object FlutterSpTransfer {

    private const val TAG = "FlutterSpTransfer"

    fun transfer(context: Context) {
        val now = System.currentTimeMillis()
        val flutterSp = context.getSharedPreferences(
            "FlutterSharedPreferences",
            Context.MODE_PRIVATE
        )
        val flutterUserToken = flutterSp.getString("flutter.RtEnv.currUserToken", "")
        if (flutterUserToken?.isNotEmpty() == true) {
            SkStorage.put(StorageKeys.CUR_USER_TOKEN, flutterUserToken)
            flutterSp.edit().remove("flutter.RtEnv.currUserToken").apply()
//            val code = SkStorage.mmkv.importFromSharedPreferences(flutterSp)
        }

        Log.d(TAG, fun(): String {
            return SkStorage.getString(StorageKeys.CUR_USER_TOKEN, null) ?: ""
        }.invoke())
        Log.d(TAG, "${System.currentTimeMillis() - now} ms")
    }

}